package com.agileboot.attendance.domain.supplier.model;

import com.agileboot.attendance.domain.personnel.db.AttPersonnelService;
import com.agileboot.attendance.domain.supplier.db.AttSupplierEntity;
import com.agileboot.attendance.domain.supplier.db.AttSupplierService;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 供应商模型工厂类
 * </p>
 *
 * @author agileboot
 * @since 2023-03-14
 */
@Component
@RequiredArgsConstructor
public class SupplierModelFactory {

    private final AttSupplierService supplierService;
    private final AttPersonnelService personnelService;

    /**
     * 创建空的供应商模型
     *
     * @return 供应商模型
     */
    public SupplierModel create() {
        return new SupplierModel(supplierService, personnelService);
    }

    /**
     * 根据ID加载供应商模型
     *
     * @param supplierId 供应商ID
     * @return 供应商模型
     */
    public SupplierModel loadById(Long supplierId) {
        AttSupplierEntity entity = supplierService.getById(supplierId);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.SUPPLIER_NOT_FOUND);
        }
        return new SupplierModel(entity, supplierService, personnelService);
    }
} 